/*
 * @Author: cola(sunshiwen)
 * @Date: 2022-04-22 10:31:06
 * @LastEditTime: 2022-06-08 20:16:31
 * @LastEditors: cola(sunshiwen)
 * @Description: branchManage model
 * @FilePath: /maycur-koa/model/branchManageModel.js
 */
'use strict';
const moment = require('moment');
const Sequelize = require('sequelize');
const { Model } = Sequelize;

const mysql = require('../common/mysql');
class project extends Model { }
class masterBranchManage extends Model { }
class hybridBranchManage extends Model { }

// 项目表
project.init({
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrementIdentity: true,
    },
    name: {
        type: Sequelize.STRING,
    },
}, {
    sequelize: mysql,
    modelName: 'projects',
    timestamps: false,
})
// 主版本分支表
masterBranchManage.init({
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrementIdentity: true,
    },
    corporation: {
        type: Sequelize.STRING,
    },
    env: {
        type: Sequelize.STRING,
    },
    branch: {
        type: Sequelize.STRING,
    },
    version: {
        type: Sequelize.STRING,
    },
    ctime: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('ctime')).format('YYYY-MM-DD HH:mm:ss');
        },
    },
    mtime: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('mtime')).format('YYYY-MM-DD HH:mm:ss');
        },
    },
    pid: {
        type: Sequelize.STRING,
    },
    commitId: {
        type: Sequelize.STRING,
    },
    person: {
        type: Sequelize.STRING,
    }
}, {
    sequelize: mysql,
    modelName: 'master_manages',
    timestamps: false,
})
// 混合云分支表
hybridBranchManage.init({
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrementIdentity: true,
    },
    corporation: {
        type: Sequelize.STRING,
    },
    env: {
        type: Sequelize.STRING,
    },
    branch: {
        type: Sequelize.STRING,
    },
    version: {
        type: Sequelize.STRING,
    },
    nextVersion: {
        type: Sequelize.STRING,
    },
    ctime: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('ctime')).format('YYYY-MM-DD HH:mm:ss');
        },
    },
    mtime: {
        type: Sequelize.DATE,
        get() {
            return moment(this.getDataValue('mtime')).format('YYYY-MM-DD HH:mm:ss');
        },
    },
    pid: {
        type: Sequelize.STRING,
    },
    commitId: {
        type: Sequelize.STRING,
    },
    remark: {
        type: Sequelize.STRING,
    }
}, {
    sequelize: mysql,
    modelName: 'hybrid_manages',
    timestamps: false,
});

module.exports = {
    project,
    masterBranchManage,
    hybridBranchManage,
};